home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS / PCCTS last-minute bug fix < prev    next >
Encoding:
Text File  |  1994-09-16  |  4.6 KB  |  174 lines  |  [TEXT/????]

  1. Newsgroups: comp.compilers.tools.pccts
  2. Path: gallant.apple.com!murky.apple.com!decwrl!pacbell.com!well!barrnet.net!agat
  3. e!howland.reston.ans.net!europa.eng.gtefsd.com!newsxfer.itd.umich.edu!zip.eecs.u
  4. mich.edu!umn.edu!parrt
  5. From: parrt@arc.umn.edu (Terence Parr)
  6. Subject: PCCTS 1.23 code gen fix
  7. Message-ID: <Cw5437.6As@news.cis.umn.edu>
  8. Sender: news@news.cis.umn.edu (Usenet News Administration)
  9. Nntp-Posting-Host: s13.arc.umn.edu
  10. Organization: AHPCRC, University of Minnesota, Minneapolis
  11. Date: Wed, 14 Sep 1994 22:05:58 GMT
  12. Lines: 159
  13.  
  14. It turns out that I introduced this (...)* code-gen bug back in 1.20.
  15. I just happened to find it now.  For example, the following didn't
  16. generate the right code:
  17.  
  18. a : ( A | B )* A C ;
  19.  
  20. Upon 'A C', a syntax error would occur.
  21.  
  22. Terribly sorry.  I'm in the process of adding parser exception handling
  23. so will probably not put out a new release just for this bug fix.
  24.  
  25. Terence -------------------------------------
  26.  
  27. To fix things, just change the following functions in gen.c (PS: I
  28. haven't had the time to test EVERYTHING with this fix.  Use at your
  29. own risk ;).
  30.  
  31. /*
  32.  * Generate code for a loop blk of form:
  33.  *
  34.  *                 |---|
  35.  *                 v   |
  36.  *               --o-G-o-->o--
  37.  */
  38. void
  39. #ifdef __STDC__
  40. genLoopBlk( Junction *begin, Junction *q, Junction *start, int max_k )
  41. #else
  42. genLoopBlk( begin, q, start, max_k )
  43. Junction *begin;
  44. Junction *q;
  45. Junction *start;    /* where to start generating code from */
  46. int max_k;
  47. #endif
  48. {
  49.     set f;
  50.     int need_right_curly;
  51.     require(q->ntype == nJunction,    "genLoopBlk: not junction");
  52.     require(q->jtype == aLoopBlk,    "genLoopBlk: not loop block");
  53.  
  54.     if ( q->visited ) return;
  55.     q->visited = TRUE;
  56.     if ( q->p2 == NULL )    /* only one alternative? */
  57.     {
  58.         if ( DemandLookahead )
  59.             if ( !GenCC ) {gen1("LOOK(%d);\n", max_k);}
  60.             else gen1("look(%d);\n", max_k);
  61.         gen("while ( ");
  62.         if ( begin!=NULL ) genExpr(begin);
  63.         else genExpr(q);
  64.         /* if no predicates have been hoisted for this single alt (..)*
  65.          * do so now
  66.          */
  67.         if ( ParseWithPredicates && begin->predicate==NULL )
  68.         {
  69.             Predicate *a = find_predicates((Node *)q->p1);
  70.             if ( a!=NULL )
  71.             {
  72.                 _gen("&&");
  73.                 genPredTree(a, q);
  74.             }
  75.         }
  76.         _gen(" ) {\n");
  77.         tabs++;
  78.         TRANS(q->p1);
  79.         if ( !GenCC ) gen1("zzLOOP(zztasp%d);\n", BlkLevel-1);
  80.         if ( DemandLookahead )
  81.             if ( !GenCC ) {gen1("LOOK(%d);\n", max_k);}
  82.             else gen1("look(%d);\n", max_k);
  83.         --tabs;
  84.         gen("}\n");
  85.         freeBlkFsets(q);
  86.         q->visited = FALSE;
  87.         return;
  88.     }
  89.     else gen("while ( 1 ) {\n");
  90.     tabs++;
  91.     if ( begin!=NULL )
  92.     {
  93.         if ( DemandLookahead )
  94.             if ( !GenCC ) {gen1("LOOK(%d);\n", max_k);}
  95.             else gen1("look(%d);\n", max_k);
  96.         gen("if ( ");
  97.         genExpr((Junction *)begin->p2);
  98.         _gen(" ) break;\n");
  99.     }
  100.     f = genBlk(q, aLoopBlk, &max_k, &need_right_curly);
  101.     set_free(f);
  102.     freeBlkFsets(q);
  103.  
  104.     /* generate code for terminating loop (this is optional branch) */
  105.     if ( begin==NULL ) gen("else break;\n"); /* code for exiting loop "for sure" */
  106.  
  107.     { int i; for (i=1; i<=need_right_curly; i++) {tabs--; gen("}\n");} }
  108.     if ( !GenCC ) gen1("zzLOOP(zztasp%d);\n", BlkLevel-1);
  109.     --tabs;
  110.     gen("}\n");
  111.     q->visited = FALSE;
  112. }
  113.  
  114. /*
  115.  * Generate code for a loop blk of form:
  116.  *
  117.  *                          |---|
  118.  *                         v   |
  119.  *               --o-->o-->o-G-o-->o--
  120.  *                   |           ^
  121.  *                   v           |
  122.  *                     o-----------o
  123.  *
  124.  * q->end points to the last node (far right) in the blk.  Note that q->end->jtype
  125.  * must be 'EndBlk'.
  126.  *
  127.  * Generate code roughly of the following form:
  128.  *
  129.  *    do {
  130.  *        ... code for alternatives ...
  131.  *  } while ( First Set of aLoopBlk );
  132.  *
  133.  *    OR if > 1 alternative
  134.  *
  135.  *    do {
  136.  *        ... code for alternatives ...
  137.  *        else break;
  138.  *  } while ( 1 );
  139.  */
  140. void
  141. #ifdef __STDC__
  142. genLoopBegin( Junction *q )
  143. #else
  144. genLoopBegin( q )
  145. Junction *q;
  146. #endif
  147. {
  148.     set f;
  149.     int i;
  150.     int max_k;
  151.     require(q!=NULL,                "genLoopBegin: invalid node and/or rule");
  152.     require(q->ntype == nJunction,    "genLoopBegin: not junction");
  153.     require(q->jtype == aLoopBegin,    "genLoopBegin: not loop block");
  154.     require(q->p2!=NULL,            "genLoopBegin: invalid Loop Graph");
  155.  
  156.     if ( GenLineInfo ) fprintf(output, LineInfoFormatStr, q->line, FileStr[q->file]);
  157.  
  158.     BLOCK_Preamble(q);
  159.     BlkLevel++;
  160.     f = First(q, 1, aLoopBegin, &max_k);
  161.     /* If not simple LL(1), must specify to start at LoopBegin, not LoopBlk */
  162.     if ( LL_k>1 && !set_nil(q->fset[2]) )
  163.         genLoopBlk( q, (Junction *)q->p1, q, max_k );
  164.     else genLoopBlk( q, (Junction *)q->p1, NULL, max_k );
  165.  
  166.     for (i=1; i<=CLL_k; i++) set_free(q->fset[i]);
  167.     for (i=1; i<=CLL_k; i++) set_free(((Junction *)q->p2)->fset[i]);
  168.     --BlkLevel;
  169.     BLOCK_Tail();
  170.     set_free(f);
  171.     if (q->end->p1 != NULL) TRANS(q->end->p1);
  172. }
  173. ---------------------------------------------------------------------------
  174.